package com.huawei.appgallery.wishlist.ui.fragment;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.wishbase.ui.fragment.BaseWishFragment;
import com.huawei.appgallery.wishlist.api.WishInfo;
import com.huawei.appgallery.wishlist.api.WishListResBean;
import com.huawei.appgallery.wishlist.bean.WishDeleteInfo;
import com.huawei.appgallery.wishlist.control.WishListAdapter;
import com.huawei.appgallery.wishlist.ui.activity.WishAddActivityProtocol;
import com.huawei.appgallery.wishlist.ui.activity.WishAddActivityProtocol.Request;
import com.huawei.appgallery.wishlist.ui.activity.WishDetailActivityProtocol;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.List;
import o.cip;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cjp;
import o.dcc;
import o.dce.i;
import o.dce.j;
import o.dch;
import o.dcq;
import o.dda;
import o.dof;
import o.ContentManager;
import o.CollectCheck;
import o.evx;
import o.ll;

@FragmentDefine(alias = "wishlist.fragment", protocol = WishListFragmentProtocol.class)
public class WishListFragment extends BaseWishFragment {
    private long ʹ = 0;
    private String ʻᐝ;
    private WishListAdapter ʼ = null;
    private cip ʽ;
    private LinearLayout ˊ = null;
    private ListView ˋ = null;
    private cjp ˎ;
    private ViewGroup ˏ;
    private LinearLayout ॱ = null;
    private TextView ॱॱ = null;
    private HwButton ᐝ = null;
    private String ﹳ;
    private String ﾞ;
    private List<WishInfo> ﾟ = new ArrayList();

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        this.ˏ = (ViewGroup) layoutInflater.inflate(i.ˏॱ, viewGroup, false);
        this.ˏ.setBackgroundColor(ᐝॱ().getColor(a.ˎ));
        this.ॱ = (LinearLayout) this.ˏ.findViewById(e.ꓸ);
        this.ॱॱ = (TextView) this.ˏ.findViewById(e.ʾॱ);
        this.ˊ = (LinearLayout) this.ˏ.findViewById(e.ꜟ);
        this.ˋ = (ListView) this.ˏ.findViewById(e.ʹ);
        this.ʼ = new WishListAdapter(ॱˋ(), i.ˏॱ);
        if (!CollectCheck.isEmpty(this.ﾟ)) {
            this.ʼ.setWishList(this.ﾟ);
        }
        this.ˋ.setAdapter(this.ʼ);
        this.ᐝ = (HwButton) this.ˏ.findViewById(e.ॱʻ);
        this.ᐝ.setOnClickListener(new evx(this) {
            final /* synthetic */ WishListFragment ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                cjo wishAddActivityProtocol = new WishAddActivityProtocol();
                Request request = new Request();
                request.ˏ("2");
                request.ˊ("");
                wishAddActivityProtocol.ˎ(request);
                try {
                    this.ˊ.ˎ = cjk.ˎ().ˎ(this.ˊ.ॱˋ(), new cjm("create.wish.activity", wishAddActivityProtocol), 100);
                } catch (ActivityNotFoundException e) {
                    dch.ˎ.ˏ("WishListFragment", "ActivityNotFoundException :" + e.toString());
                }
            }
        });
        if (ʼʻ()) {
            ʿॱ();
        } else {
            ʽᐝ();
        }
        this.ˋ.setOnItemClickListener(new OnItemClickListener(this) {
            final /* synthetic */ WishListFragment ˏ;

            {
                this.ˏ = r1;
            }

            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                long currentTimeMillis = System.currentTimeMillis();
                if (currentTimeMillis - this.ˏ.ʹ > 1000) {
                    this.ˏ.ʹ = currentTimeMillis;
                    ˋ(i);
                    cjo wishDetailActivityProtocol = new WishDetailActivityProtocol();
                    WishDetailActivityProtocol.Request request = new WishDetailActivityProtocol.Request();
                    request.ˋ(((WishInfo) this.ˏ.ﾟ.get(i)).ˏ());
                    request.ˊ(((WishInfo) this.ˏ.ﾟ.get(i)).ˊ());
                    request.ˎ(((WishInfo) this.ˏ.ﾟ.get(i)).ʽ());
                    wishDetailActivityProtocol.ˋ(request);
                    cjk.ˎ().ˋ(this.ˏ.ॱˋ(), new cjm("wish.detail.activity", wishDetailActivityProtocol));
                }
            }

            private void ˋ(int i) {
                if (i < this.ˏ.ʼ.getCount()) {
                    Object item = this.ˏ.ʼ.getItem(i);
                    if (item instanceof WishInfo) {
                        ((WishInfo) item).ˎ(0);
                        this.ˏ.ʼ.notifyDataSetChanged();
                    }
                }
            }
        });
        this.ˋ.setOnItemLongClickListener(new OnItemLongClickListener(this) {
            final /* synthetic */ WishListFragment ˎ;

            {
                this.ˎ = r1;
            }

            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (!CollectCheck.isEmpty(this.ˎ.ﾟ)) {
                    String ˏ = ((WishInfo) this.ˎ.ﾟ.get(i)).ˏ();
                    List arrayList = new ArrayList();
                    for (WishInfo wishInfo : this.ˎ.ﾟ) {
                        WishDeleteInfo wishDeleteInfo = new WishDeleteInfo();
                        if (!dof.ॱ(ˏ) && ˏ.equals(wishInfo.ˏ())) {
                            wishDeleteInfo.ˊ(true);
                        }
                        wishDeleteInfo.ˎ(wishInfo.ˏ());
                        wishDeleteInfo.ˊ(wishInfo.ˊ());
                        wishDeleteInfo.ॱ(wishInfo.ˎ());
                        arrayList.add(wishDeleteInfo);
                    }
                    dda.ॱ().ˏ(arrayList);
                    try {
                        this.ˎ.ˎ = cjk.ˎ().ˎ(this.ˎ.ॱˋ(), new cjm("delete.wish.activity", null), (int) DialogButton.CONFIRM);
                    } catch (ActivityNotFoundException e) {
                        dch.ˎ.ˏ("WishListFragment", "ActivityNotFoundException :" + e.toString());
                    }
                }
                return true;
            }
        });
        return this.ˏ;
    }

    public void ˋ(int i) {
        if (ॱ() != null) {
            ॱ().ˊ(this, !CollectCheck.isEmpty(this.ﾟ));
        }
    }

    public void ʼᐝ() {
        super.ʼᐝ();
        List arrayList = new ArrayList();
        for (WishInfo wishInfo : this.ﾟ) {
            WishDeleteInfo wishDeleteInfo = new WishDeleteInfo();
            wishDeleteInfo.ˎ(wishInfo.ˏ());
            wishDeleteInfo.ˊ(wishInfo.ˊ());
            wishDeleteInfo.ॱ(wishInfo.ˎ());
            arrayList.add(wishDeleteInfo);
        }
        dda.ॱ().ˏ(arrayList);
        try {
            this.ˎ = cjk.ˎ().ˎ(ॱˋ(), new cjm("delete.wish.activity", null), (int) DialogButton.CONFIRM);
        } catch (ActivityNotFoundException e) {
            dch.ˎ.ˏ("WishListFragment", "ActivityNotFoundException :" + e.toString());
        }
    }

    private void ʽᐝ() {
        if (this.ʽ == null) {
            this.ʽ = new cip();
            this.ʽ.ˎ(this.ˏ.findViewById(e.ㆍ));
            this.ʽ.ˋ(new OnClickListener(this) {
                final /* synthetic */ WishListFragment ˊ;

                {
                    this.ˊ = r1;
                }

                public void onClick(View view) {
                    this.ˊ.ʿˊ();
                }
            });
        }
        this.ʽ.ॱ(0);
    }

    private void ˊʼ() {
        if (this.ʽ != null) {
            this.ʽ.ॱ(8);
            this.ʽ = null;
        }
    }

    private void ʿॱ() {
        ˊʼ();
        this.ʼ.clearCache();
        if (CollectCheck.isEmpty(this.ﾟ)) {
            dch.ˎ.ˋ("WishListFragment", "show wishList size:0");
            if (TextUtils.isEmpty(this.ﹳ)) {
                this.ॱॱ.setText(j.ʽ);
            } else {
                this.ॱॱ.setText(this.ﹳ);
            }
            ˎ(this.ॱ, 0);
            ˎ(this.ˊ, 8);
            if (ॱ() != null) {
                ॱ().ˊ(this, false);
            }
        } else {
            ˎ(this.ॱ, 8);
            ˎ(this.ˊ, 0);
            if (ॱ() != null) {
                ॱ().ˊ(this, true);
            }
            for (WishInfo wishInfo : this.ﾟ) {
                if (wishInfo != null) {
                    this.ʼ.addData(wishInfo);
                }
            }
        }
        if (ॱˋ() instanceof dcc) {
            ((dcc) ॱˋ()).d_(this.ﾞ);
        }
        if (TextUtils.isEmpty(this.ʻᐝ)) {
            this.ᐝ.setText(j.ˉ);
        } else {
            this.ᐝ.setText(this.ʻᐝ);
        }
        this.ʼ.notifyDataSetChanged();
    }

    private void ˎ(View view, int i) {
        if (view != null && view.getVisibility() != i) {
            view.setVisibility(i);
        }
    }

    public void ˋ(TaskFragment taskFragment, List list) {
        list.add(new dcq(-1));
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        WishListResBean wishListResBean = (WishListResBean) bVar.ˋ;
        if (wishListResBean.getResponseCode() == 0 && wishListResBean.getRtnCode_() == 0) {
            ॱˋ(true);
            this.ﾟ = wishListResBean.ˏ();
            this.ﹳ = wishListResBean.ˋ();
            this.ﾞ = wishListResBean.ˊ();
            this.ʻᐝ = wishListResBean.ˎ();
            dda.ॱ().ˋ(this.ﾟ);
            if (ʾ()) {
                ˎ(this.ᐝ, 0);
                ʿॱ();
            }
        } else if (this.ʽ != null) {
            ˎ(this.ॱ, 8);
            ˎ(this.ˊ, 8);
            ˎ(this.ᐝ, 8);
            this.ʽ.ˏ(wishListResBean.getResponseCode(), true);
        }
        return false;
    }

    public void ॱ(int i, int i2, Intent intent) {
        super.ॱ(i, i2, intent);
        if (this.ˎ != null && -1 == i2 && this.ˎ.ˋ() == i) {
            ʽᐝ();
            ʿˊ();
            Intent intent2 = new Intent();
            intent2.setAction("action_online_brd_refresh_list");
            ll.ˏ(ContentManager.getInstant().getContext()).ˋ(intent2);
        }
    }
}
